#!/bin/bash

PORT=27017
USERNAME=admin
PASSWORD=111111
TAG=latest

while getopts "p:u:a:t:" opt; do
  case $opt in
    p)
        PORT=$OPTARG
        ;;
    u)
        USERNAME=$OPTARG
        ;;
    a)
        PASSWORD=$OPTARG
        ;;
    t)
        TAG=$OPTARG
        ;;
    \?)
        echo "invalid arg"
        exit 1
        ;;
  esac
done

docker run \
--restart always \
--name mongo-server \
-p ${PORT}:27017 \
-v ${PWD}/data:/data/db \
-e MONGO_INITDB_ROOT_USERNAME=${USERNAME} \
-e MONGO_INITDB_ROOT_PASSWORD=${PASSWORD} \
-d mongo:${TAG}